<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
$store_id=$this->session('store_id');
if(!$store_id){
	exi('请先选择场馆！','error');
}
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
if($_RQ['op']=='main'){
	//查询所有未锁定服务员工
	$worker_list=pdo_getall('jy_qiuyuyue_store_worker',array('uniacid'=>$_SESSION['uniacid'],'store_id'=>$store_id,'islock'=>'0'));
	if($worker_list){
		foreach($worker_list as &$item){
			$item['lev_name']=pdo_getcolumn('jy_qiuyuyue_lev',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['lev']),'lev_name');
		    //已支付，已确认，已完成订单数
			$num1=pdo_count('jy_qiuyuyue_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id'],'status'=>'1'));
			$num2=pdo_count('jy_qiuyuyue_server_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id'],'status'=>'2'));
			$num3=pdo_count('jy_qiuyuyue_server_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id'],'status'=>'4'));
			$item['num']=$num1+$num2+$num3;
		}
	}
	$return['pcd']=array(
		'province' =>trim($_RQ['province']),
		'city' =>trim($_RQ['city']),
		'district' =>trim($_RQ['district']),
	);
	$return['post']=array('dayid'=>0);
	$return['params']=array('order'=>'default');
	$return['worker_list']=$worker_list;
	$htmltitle = $return['basic']['title'];
	$share_desc = $return['basic']['share_desc'];
	$share_image = $return['basic']['share_image'];
	$return['sharedata']=array(
			'title'=>'技师列表',
			'desc'=>$share_desc?:'上门服务，技师入驻，经络排毒，活血化瘀！',
			'link'=>custom_url('jy_qiuyuyue/worker//&fromuser='.$_SESSION['uid'].'&current_plugin='.$_SESSION['current_plugin'],true),
			'imgUrl'=>ATTACHMENT_URL.$share_image,
	);
	set_html('title','技师列表');
	exi($return);
}
if($_RQ['op']=='list'){

	exi($return);
}
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
		exi('请先选择员工','error','goback');
	}
	pdo_update('jy_qiuyuyue_store_worker',array('looks +='=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//查询该员工具体信息
	$worker=pdo_get('jy_qiuyuyue_store_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	if(!$worker){
		exi('没有找到该员工，请重新选择！','error','goback');
	}
	$worker['lat_lng']=$worker['lat_lng']?:'{}';
	$worker['lat_lng']=json_decode($worker['lat_lng'],true);
	$worker['hdps']=json_decode($worker['hdps'],true);
	$worker['sales']=pdo_count('jy_qiuyuyue_server_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>4,'worker_id'=>$v['id']),'id');

	//等级名称
	$lev_name=pdo_getcolumn('jy_qiuyuyue_lev',array('uniacid'=>$_SESSION['uniacid'],'id'=>$worker['lev_id']),'lev_name');
	//日期 今天，未来七天
	$data=array();
	$data['0']['riqi']=date("m-d",time("day")); 
	$data['1']['riqi']=date("m-d",strtotime("+1 day")); 
	$data['2']['riqi']=date("m-d",strtotime("+2 day")); 
	$data['3']['riqi']=date("m-d",strtotime("+3 day")); 
	$data['4']['riqi']=date("m-d",strtotime("+4 day")); 
	$data['5']['riqi']=date("m-d",strtotime("+5 day")); 
	$data['6']['riqi']=date("m-d",strtotime("+6 day")); 
	$weekarray=array("日","一","二","三","四","五","六"); //先定义一个数组
	$data['0']['xinq']= "星期".$weekarray[date("w")];
	$data['1']['xinq']= "星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+1 day"))))];
	$data['2']['xinq']= "星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+2 day"))))];
	$data['3']['xinq']= "星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+3 day"))))];
	$data['4']['xinq']= "星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+4 day"))))];
	$data['5']['xinq']= "星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+5 day"))))];
	$data['6']['xinq']= "星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+6 day"))))];
	//可服务项目
	$services=explode(";",$worker['service']);
	$services=array_filter($services);
	$service=array();
	foreach($services as &$item){
		$item=pdo_get('jy_qiuyuyue_store_serve',array('uniacid'=>$_SESSION['uniacid'],'serve_id'=>$item));	
		
		if($item['status']==1){
			$serv=pdo_get('jy_qiuyuyue_serve',array('id'=>$item['serve_id']));
			$item=array_merge($item,$serv);
			$item['package']=json_decode($item['package'],true);
			array_push($service,$item);
		}
		
	}
	$return['worker']=$worker;
	$return['service']=$service;
	$return['data']=$data;
	$return['post']=array(
		'dayid'=>0,
		'store_id'=>$store_id,
		'worker_id'=>$_RQ['id'],
	);
	$this->session('worker_id',$_RQ['id']);
	$return['sharedata']=array(
			'title'=>'技师-'.$worker['name'],
			'desc'=>$worker['remark']?:'上门服务，技师入驻，经络排毒，活血化瘀！',
			'link'=>custom_url('jy_qiuyuyue/worker/detail/id='.$worker['id'].'&fromuser='.$_SESSION['uid'].'&current_plugin='.$_SESSION['current_plugin'],true),
			'imgUrl'=>ATTACHMENT_URL.$worker['headimg'],
	);
	set_html('title','技师详情');
	exi($return);
}